<template>
  <div class="page">
    <!-- 顶部栏 -->
    <van-nav-bar fixed placeholder :border="false">
      <template #title>
        <div class="fz-16 fw-bold">买入卖出明细</div>
      </template>
    </van-nav-bar>

    <div class="container">
      <!-- 订单列表 -->
      <ul v-if="orders.length">
        <li
          class="box box--bg cl-white lh-2 mb-10"
          v-for="(v, i) in orders"
          :key="i"
        >
          <div class="flex flex-rb">
            <div>
              <span>类型：</span>
              <span>{{ types[v.type] }}</span>
            </div>

            <div v-if="v.type === 1">
              <span>实际支付：</span>
              <span>{{ v.tradeAmount }}U</span>
            </div>

            <div v-else>
              <span>确认克数：</span>
              <span>{{ v.tradeAmount }}克</span>
            </div>
          </div>

          <div class="flex flex-rb">
            <div>
              <span>成交金价：</span>
              <span>{{ v.goldPrice }}</span>
            </div>

            <div v-if="v.type === 1">
              <span>手续费：</span>
              <span>{{ v.fees }}</span>
            </div>
          </div>

          <div class="flex flex-rb">
            <div>
              <span>买入时间：</span>
              <span>{{ v.createTime }}</span>
            </div>

            <div>
              <span>确认时间：</span>
              <span>{{ v.effectiveTime }}</span>
            </div>
          </div>
        </li>
      </ul>

      <!-- 暂无数据 -->
      <van-empty v-else>
        <span class="cl-white">暂无数据</span>
      </van-empty>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import goldApi from 'js/gold.api'

const orders = ref([])

const types = ref({
  1: '买入',
  2: '卖出',
})

getGoldOrderList()

// 获取理财产品订单列表
async function getGoldOrderList() {
  const params = {
    financialProductId: 1,
    status: 1,
    type: 1,
    current: 1,
    size: 100000,
  }

  const { code, data } = await goldApi.getGoldOrderList(params)

  if (code === 200) {
    orders.value = data.records || []
  }
}
</script>

<style lang="scss" scoped></style>
